package com.example.scity;

import android.content.Context;
import android.content.SharedPreferences;

public class Configs {
    final static String FileName = "Configs";
    final static String KEY_IP = "key_IP";
    final static String KEY_PORT = "key_PORT";
    final static String Load_Times = "Load_Times";
    final static String LoadValue = "sencode";
    public static String Host = "";
    public static String mIp;
    public static String mPort;
    final static String TAG = "SCITYDDD";
    public static String Token = "";
    public static String AUKEY = "Authorization";
    //读取ip和端口
    public static void ReadIp(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences(FileName,Context.MODE_PRIVATE);
        mIp = sharedPreferences.getString(KEY_IP,"");
        mPort = sharedPreferences.getString(KEY_PORT,"");
        if(mIp == ""||mPort==""){
            mIp = "124.93.196.45";
            mPort = "10001";
        }
        Host = "http://"+mIp + ":" + mPort;
    }
    public static boolean LoadTimes(Context context){
        String rt;
        SharedPreferences sharedPreferences = context.getSharedPreferences(FileName,Context.MODE_PRIVATE);
        rt = sharedPreferences.getString(Load_Times,"");
        if(rt.equals(LoadValue)){
            return true;
        }else{
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString(Load_Times,LoadValue);
            editor.commit();
        }
        return false;
    }
    //写入
    public static void WriteIp(Context context,String ip,String port){
        SharedPreferences sharedPreferences = context.getSharedPreferences(FileName,Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        mIp = ip;
        mPort = port;
        editor.putString(KEY_IP,mIp);
        editor.putString(KEY_PORT,mPort);
        editor.commit();
        Host = "http://"+mIp + ":" + mPort;
    }
}
